unit wxhSystemID;

interface
uses
  SysUtils,
  {$IFDEF ANDROID}
  FMX.Platform.Android,
  Androidapi.JNI.Telephony,
  Androidapi.JNI.Provider ,
  Androidapi.JNIBridge,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.JavaTypes,
  Androidapi.Helpers;

function getIMEI:string;
function getAndroidID:string;
  {$ENDIF}
  {$IFDEF Win32}
  CPUID;
function getCPUID:string;
  {$ENDIF}

function getDeviceID:string;

implementation

{$IFDEF ANDROID}
function getIMEI:string;
var
  obj: JObject;
  tm: JTelephonyManager;
begin
  Result:='';
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE);
  if obj <> nil then
  begin
    tm := TJTelephonyManager.Wrap( (obj as ILocalObject).GetObjectID );
    if tm <> nil then
    try
      Result := JStringToString(tm.getDeviceId);
    except

    end;
  end;
end;

function getAndroidID:string;
begin
  Result := JStringToString(TJSettings_Secure.JavaClass.getString(SharedActivity.getContentResolver, TJSettings_Secure.JavaClass.ANDROID_ID));
  Result:=SysUtils.UpperCase(Result);
end;

function getDeviceID:string;
begin
  result:=getAndroidID;
end;

{$ENDIF}

{$IFDEF Win32}
function getCPUID:string;
var
  id:NativeUInt;
  t: TCPUIDStruct;
begin
  id:=1;
  CPUID.CallCPUID(id,t);
  Result:=IntToHex(t.rEAX,4)+IntToHex(t.rEBX,4)+IntToHex(t.rECX,4)+IntToHex(t.rEDX,4);
end;

function getDeviceID:string;
begin
  result:=getCPUID;
end;
{$ENDIF}

end.
